From: Keir Fraser Date: Tue, 19 May 2009 00:34:34 +0000 (+0100) Subject: xend: Avoid deprecation warnings with Python 2.6. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13917 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=fdaaa5fe16b80537af735462993877658dff4869;p=xen.git xend: Avoid deprecation warnings with Python 2.6. Signed-off-by: Brendan Cully --- diff --git a/tools/python/xen/util/acmpolicy.py b/tools/python/xen/util/acmpolicy.py index 1a95c3a2d5..6752169c7b 100644 --- a/tools/python/xen/util/acmpolicy.py +++ b/tools/python/xen/util/acmpolicy.py @@ -17,12 +17,19 @@ #============================================================================ import os -import sha import stat import array import struct import shutil import commands + +# sha is deprecated as of python 2.6 +try: + from hashlib import sha1 +except ImportError: + # but hashlib was only added in python 2.5 + from sha import new as sha1 + from xml.dom import minidom, Node from xen.xend.XendLogging import log from xen.util import xsconstants, bootloader, mkdir @@ -1102,8 +1109,8 @@ class ACMPolicy(XSPolicy): return None def hash(self): - """ Calculate a SAH1 hash of the XML policy """ - return sha.sha(self.toxml()) + """ Calculate a SHA1 hash of the XML policy """ + return sha1(self.toxml()) def save(self): ### Save the XML policy into a file ### diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index 07e6b2100e..6dda3a9c79 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -18,7 +18,6 @@ import inspect import os import Queue -import sets import string import sys import traceback @@ -26,6 +25,12 @@ import threading import time import xmlrpclib +# sets is deprecated as of python 2.6, but set is unavailable in 2.3 +try: + set +except NameError: + from sets import Set as set + import XendDomain, XendDomainInfo, XendNode, XendDmesg import XendLogging, XendTaskManager, XendAPIStore @@ -119,16 +124,17 @@ event_registrations = {} def event_register(session, reg_classes): if session not in event_registrations: event_registrations[session] = { - 'classes' : sets.Set(), + 'classes' : set(), 'queue' : Queue.Queue(EVENT_QUEUE_LENGTH), 'next-id' : 1 } if not reg_classes: reg_classes = classes - if hasattr(set, 'union_update'): - event_registrations[session]['classes'].union_update(reg_classes) + sessionclasses = event_registrations[session]['classes'] + if hasattr(sessionclasses, 'union_update'): + sessionclasses.union_update(reg_classes) else: - event_registrations[session]['classes'].update(reg_classes) + sessionclasses.update(reg_classes)